package com.wms.login.action;

import org.apache.log4j.Logger;

import com.wms.common.model.SessionUserInfo;
import com.wms.common.web.action.CIBaseAction;
import com.wms.login.service.LoginService;

public class LoginAction extends CIBaseAction {
	private Logger logger = Logger.getLogger(this.getClass());
	
	private LoginService loginService;

	private String username;
	private String password;

	public String toLogin() throws Exception {	
		return SUCCESS;
	}
	
	public String doLogin() throws Exception {
		loginService.authenticate(username, password);
		SessionUserInfo userInfo = new SessionUserInfo();
		userInfo.setUsername(username);
		userInfo.setPassword(password);
		this.setSessionUserInfo(userInfo);
		return SUCCESS;
	}
	
	public String doLogout() throws Exception{
		this.setSessionUserInfo(null);
		session.invalidate();
		return SUCCESS;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public String getPassword() {
		return password;
	}

	public void setUsername(String username) {
		this.username = username;
	}

	public String getUsername() {
		return username;
	}

	public void setLoginService(LoginService loginService) {
		this.loginService = loginService;
	}

	public LoginService getLoginService() {
		return loginService;
	}

}
